﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PloobsEngine;
using PloobsEngine.SceneControl;
using PloobsEngine.Utils;
using Etapa1.Baker;
using PloobsEngine.Cameras;
using PloobsEngine.Material;
using PloobsEngine.Modelo;
using PloobsEngine.Input;

namespace Etapa1.Screens
{
    public class BakerScreen : IScreen
    {
        public BakerScreen()
            : base()
        {            
        }

        BakerShader bs;
        IObject obj;
        ICamera cam;
        RenderTarget2D rt;
        public override void LoadContent(EngineStuff es)
        {
            base.LoadContent(es);
            bs = new BakerShader();
            rt = EngineStuff.GetDefaultColorBuffer();
            cam = new CameraFirstPerson();
            SimpleModel sm = new SimpleModel("..\\Content\\Model\\cenario");
            sm.LoadModelo();                                                
            obj = new SimpleObject();
            obj.Modelo = sm;

            es.AddComponent(new InputAdvanced(es));
        }
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
            cam.Update(gameTime);
        }
       
        public override void Draw(GameTime gameTime)
        {
            EngineStuff.GraphicsDevice.RenderState.CullMode = CullMode.None;
            EngineStuff.GraphicsDevice.RenderState.DepthBufferEnable = false;

            EngineStuff.GraphicsDevice.SetRenderTarget(0, rt);
            EngineStuff.GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.Black, 1, 0);
            bs.Draw(obj, obj.Modelo, cam);
            EngineStuff.GraphicsDevice.SetRenderTarget(0, null);

            EngineStuff.GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.Black,1,0);
            EngineStuff.SpriteBatch.Begin();
            EngineStuff.SpriteBatch.Draw(rt.GetTexture(), Vector2.Zero, Color.White);
            EngineStuff.SpriteBatch.End();            
            base.Draw(gameTime);

        }        
    }
        
}

